########################################################
### Varieties of Economic Vulnerability  				 			 
### Melina Altamirano, Sarah Berens & Franziska Deeg 	 			 
### March 2021         											 
### Conjoint Analysis
########################################################

###Only analysis: For final plots see PlotFile###
##Estimates for Figure B Appendix: Conjoint: Results for Average Respondent
generalset <- subset(Conjoint_no_NA, chosen_profile <= 1, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
generalset <- na.omit(generalset)
generalresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=generalset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(generalresults)
plot(generalresults, main = "Conjoint Main Results", col=gray.colors(4, start = 0.7, end = 0),
     #xlim = c(-0.2, 0.2), breaks = c(-0.2, 0.2),
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"), 
     group.order = c("Policy", "Access", "Benefits", "Finance"))


##Estimates for Figure 4: Conjoint: Formal and Informal Sector Workers 
formalset <- subset(Conjoint_no_NA, Informal==0, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
formalset <- na.omit(formalset)
formalresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=formalset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(formalresults)
plot(formalresults, main = "Conjoint Formal Workers", col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))

informalset <- subset(Conjoint_no_NA, Informal==1, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
informalset <- na.omit(informalset)
informalresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=informalset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(informalresults)
plot(informalresults, main = "Conjoint Informal Workers", col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))


##Estimates Figure 5: Conjoint: Future Employment Expectations
fortoinforlikelyset <- subset(Conjoint_no_NA, formaltoinformal==1, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
fortoinforlikelyset <- na.omit(fortoinforlikelyset)
fortoinforlikelyresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=fortoinforlikelyset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(fortoinforlikelyresults)
plot(fortoinforlikelyresults, main = "Conjoint Likely Formal to Informal", col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))

infortoforlikelyset <- subset(Conjoint_no_NA, informaltoformal==1, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
infortoforlikelyset <- na.omit(infortoforlikelyset)
infortoforlikelyresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=infortoforlikelyset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(infortoforlikelyresults)
plot(infortoforlikelyresults, main = "Conjoint Likely Informal to Formal", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))


###Estimates for Figure E Appendix: Conjoint: Household Constellations: Purely Formal HH and Informal HH
purleyinformalset <- subset(Conjoint_no_NA, household4==1, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
purleyinformalset <- na.omit(purleyinformalset)
purleyinformalresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=purleyinformalset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(purleyinformalresults)
plot(purleyinformalresults, main = "Conjoint Purley Informal Households", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))

purleyformalset <- subset(Conjoint_no_NA, household4==2, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
purleyformalset <- na.omit(purleyformalset)
purleyformalresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=purleyformalset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(purleyformalresults)
plot(purleyformalresults, main = "Conjoint Purley Formal Households", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))

###Estimates for Figure F Appendix: Conjoint: Household Constellations: Mixed Households
mixedhouse_formalrespset <- subset(Conjoint_no_NA, household4==3, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
mixedhouse_formalrespset <- na.omit(mixedhouse_formalrespset)
mixedhouse_formalrespresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=mixedhouse_formalrespset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(mixedhouse_formalrespresults)
plot(mixedhouse_formalrespresults, main = "Conjoint Mixed Households with formal respondent", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))

mixedhouse_informalrespset <- subset(Conjoint_no_NA, household4==4, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
mixedhouse_informalrespset <- na.omit(mixedhouse_informalrespset)
mixedhouse_informalrespresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=mixedhouse_informalrespset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(mixedhouse_informalrespresults)
plot(mixedhouse_informalrespresults, main = "Conjoint Mixed Households with informal respondent", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))


###Estimates for Figure G Appendix: Conjoint: Vote Choice
PANvoteset <- subset(Conjoint_no_NA, vote_choice == 2, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
PANvoteset <- na.omit(PANvoteset)
PANvoteresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=PANvoteset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(PANvoteresults)
plot(PANvoteresults, main = "Mexico Conjoint Vote Choice=PAN", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))

PRIvoteset <- subset(Conjoint_no_NA, vote_choice == 3, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
PRIvoteset <- na.omit(PRIvoteset)
PRIvoteresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=PRIvoteset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(PRIvoteresults)
plot(PRIvoteresults, main = "Mexico Conjoint Vote Choice=PRI", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))

AMLOvoteset <- subset(Conjoint_no_NA, vote_choice == 4, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
AMLOvoteset <- na.omit(AMLOvoteset)
AMLOvoteresults <- amce(chosen_profile ~ Policy + Access + Benefits + Finance, data=AMLOvoteset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(AMLOvoteresults)
plot(AMLOvoteresults, main = "Mexico Conjoint Vote Choice=Morena", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"),
     group.order = c("Policy", "Access", "Benefits", "Finance"))


###Estimates for Figure C Appendix: Conjoint: Interaction of Access and Financing 
informalset <- subset(Conjoint_no_NA, Informal == 1, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
informalset <- na.omit(informalset)
informalinteraction5_results <- amce(chosen_profile ~ Policy + Finance:Access + Benefits, data=informalset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(informalinteraction5_results)
plot(informalinteraction5_results, main = "Conjoint Access and Finance interacted, Informals", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"))

formalset <- subset(Conjoint_no_NA, Informal == 0, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
formalset <- na.omit(formalset)
formalinteraction5_results <- amce(chosen_profile ~ Policy + Finance:Access + Benefits, data=formalset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(formalinteraction5_results)
plot(formalinteraction5_results, main = "Conjoint Access and Finance interacted, Formals", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"))



###Estimates for Figure D Appendix: Conjoint: Interaction of Policy and Expansion vs Retrenchment 
informalset <- subset(Conjoint_no_NA, Informal == 1, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
informalset <- na.omit(informalset)
informalinteraction3_results <- amce(chosen_profile ~ Policy:Benefits + Access + Finance, data=informalset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(informalinteraction3_results)
plot(informalinteraction3_results, main = "Conjoint Policy and Benefits interacted, Informals", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"))


formalset <- subset(Conjoint_no_NA, Informal == 0, select = c(resp_id, Policy, Access, Benefits, Finance, chosen_profile))
formalset <- na.omit(formalset)
formalinteraction3_results <- amce(chosen_profile ~ Policy:Benefits + Access + Finance, data=formalset, cluster = TRUE, respondent.id ="resp_id", na.ignore=TRUE)
summary(formalinteraction3_results)
plot(formalinteraction3_results, main = "Conjoint Policy and Benefits interacted, Formals", 
     col=gray.colors(4, start = 0.7, end = 0), 
     plot.theme = theme_bw(base_size = 9) + theme(legend.position = "none"))



